const express = require('express');
const multer = require('multer');
const { askAI } = require('../ai');
const router = express.Router();
const upload = multer({ storage: multer.memoryStorage() });

router.post('/generate-report', upload.none(), async (req, res) => {
    console.log('generate-report');
    const model = 'qwen-max';
    const prompt = req.body.prompt;
    const completion = await askAI({ model, prompt });

    try {
      const [choice] = completion.choices;
      if(choice.message && choice.message.content){
        const { content } = choice.message;
        res.json({ code: 200, message: '生成成功', result: content });
      }else{
        res.json({ code: 500, message: '生成失败' });
      }
    } catch (error) {
      console.log('normalCompletion 解析失败')
      console.log(error);
      res.json({ code: 500, message: '解析失败' });
    }
});

module.exports = router;
